{% extends 'website/src/base.html' %}
{% block style %}
<style>

/* 竖分割线 */
.vertical-line {
    border-right: 2px solid rgba(255, 255, 255, 0.1); /* 设置右边框为竖线 #262729 #6c757d*/
    height: 100%; /* 垂直拉伸至面板的100%高度 */
    box-shadow: /* 阴影效果 */ 0 0 0 0 rgba(255, 255, 255, 0.1), /* 顶部阴影 */ 0 1px 0 0 rgba(255, 255, 255, 0.1), /* 顶部阴影 */ 0 0 2px 0 rgba(0, 0, 0, 1); /* 底部阴影 */
    transform: translateZ(0); /* 使用transform的translateZ创建深度效果 */
    transform-origin: center; /* 设置变形的原点 */
    transition: transform 0.2s; /* 添加过渡动画 */
}

.dashboard { /* 仪表盘样式 */
    display: flex;
    justify-content: center; /* 水平居中 */
    align-items: center; /* 垂直居中 */
    height: 40vh; /* 使div占满整个视口高度 */
}

.dashboard-boot { /* 仪表盘样式 */
    display: flex;
    justify-content: center; /* 水平居中 */
    align-items: center; /* 垂直居中 */
    height: 45vh; /* 使div占满整个视口高度 */
}
.dashboard-right1 { /* 仪表盘样式 */
    display: flex;
    justify-content: center; /* 水平居中 */
    align-items: center; /* 垂直居中 */
    height: 28vh; /* 使div占满整个视口高度 */
}

.dashboard-right2-1 { /* 仪表盘样式 */
    display: flex;
    justify-content: center; /* 水平居中 */
    align-items: center; /* 垂直居中 */
    height: 19vh; /* 使div占满整个视口高度 */
}
.dashboard-right2-2 { /* 仪表盘样式 */
    display: flex;
    justify-content: center; /* 水平居中 */
    align-items: center; /* 垂直居中 */
    height: 11vh; /* 使div占满整个视口高度 */
}

/* 降水量刻度尺 */
.progress {
    {#height: 10px;#}
    background-color: #f5f5f5;
    -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, .1);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, .1);
    overflow: visible;
    border-radius: 20px;
    margin: 40px 20px;
}

.progress .progress-bar {
    position: relative;
    float: left;
    width: 0;
    height: 100%;
    font-size: 12px;
    line-height: 20px;
    color: #fff;
    text-align: center;
    -webkit-box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .15);
    box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .15);
    -webkit-transition: width .6s ease;
    -o-transition: width .6s ease;
    transition: width .6s ease;
    border-radius: 10px;
    {#background-color: #001ff8;#}
}

.progress .progress-value {
    box-sizing: border-box;
    background-clip: content-box;
    display: block;
    height: 42px;
    line-height: 38px;
    width: 42px;
    text-align: center;
    border-radius: 50%;
    font-size: 13px;
    color: #fff;
    padding: 2px;
    background-color: #214eff;
    border: 1px solid #214eff;
    position: absolute;
    top: 65%;
    {#right: 20%;#}
}

.progress .progress-value:after {
    content: "";
    border-bottom: 10px solid #214eff;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    position: absolute;
    {#bottom: 40px;#}
    left: 12px;
    top: -10px;
}

</style>
{#    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css">#}
{#<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">#}
<link rel="stylesheet" href="{% static '/bootstrap-icons-1.11.3/font/bootstrap-icons.css' %}">

<link rel="stylesheet" href="/static/font-awesome-4.7.0/css/font-awesome.min.css">

{% endblock %}

{% block main %}

<div class="container-fluid panel m-3" style="border-radius: 10px; border: 1px solid #313438; background-color: #2c2d2f">

  <div class="row">
        <!-- 左边,占宽度7格 -->
        <div class="panel-body col-md-7">
            <!-- 左边上半部分,最高气温 和 最低气温仪表盘 -->
            <div class="row">
                <!-- 最高气温 -->
                <div class="dashboard vertical-line col-md-6">
                    <div id="temperature-chart" class="" style="width: 300px; height: 300px;"></div>
{#                    <p id="temperatureP" style="display: block">{{ weather_now.high }}</p>#}
                    <p id="temperatureP" style="display: block">3.8</p>
                </div>
                <!-- 最低气温 -->
                <div class="dashboard vertical-line col-md-6">
                    <div id="humidity-chart" class="" style="width: 300px; height: 300px;">{{ weather_now.low }}</div>
{#                    <p id="humidityP" style="display: block">{{ weather_now.low }}</p>#}
                    <p id="humidityP" style="display: block">22</p>
                </div>
            </div>
            <!-- 左边下半部分，降水量，降水概率，风速 -->
            <div class="row">
                <!-- 降水量 -->
                <div class="dashboard-boot vertical-line col-md-4">
                    <div class="col-md-12">
{#                        <div class="row text-white justify-content-center">降水量</div>#}
                        <div class="row text-white justify-content-center">低功耗</div>
{#                        <div class="row text-gray justify-content-center">Precipitation</div>#}
                        <div class="row text-gray justify-content-center">Low-Power Consumption</div>
{#                        <div class="row justify-content-center mt-2" style="color: #2ab62b; font-weight: bold;">{{ weather_now.rainfall }}mm</div>#}
                        <div class="row justify-content-center mt-2" style="color: #2ab62b; font-weight: bold;">0.3%</div>
                        <div class="row progress" style="height: 10px; width: 260px">
                          <div class="progress-bar" role="progressbar" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100" style="width: {{ weather_now.rainfall }}%;"></div>
{#                          <div class="progress-value" style="left: {{ rainfall_proportion }}%;">{{ weather_now.rainfall }}</div>  <!--rainfall_proportion = ma*0.78+5=left -->#}
                          <div class="progress-value" style="left: 13%;">0.3</div>  <!--rainfall_proportion = ma*0.78+5=left -->
                        </div>
                    </div>
                </div>
                <!-- 降水概率 -->
                <div class="dashboard-boot vertical-line col-md-4">
                    <div class="col-md-12">
{#                        <div class="row text-white justify-content-center">降水概率</div>#}
                        <div class="row text-white justify-content-center">高效率</div>
{#                        <div class="row text-gray justify-content-center">Precipitation Probability</div>#}
                        <div class="row text-gray justify-content-center">High Efficiency</div>
{#                        <div class="row justify-content-center mt-2" style="color: #2ab62b; font-weight: bold;">{{ weather_now.precip }}%#}
                        <div class="row justify-content-center mt-2" style="color: #2ab62b; font-weight: bold;">4%
                        </div>
                        <div class="row progress" style="height: 10px; width: 260px">
                            <div class="progress-bar" role="progressbar" aria-valuenow="50" aria-valuemin="0"
                                 aria-valuemax="100" style="width: {{ weather_now.precip }}%;"></div>
{#                            <div class="progress-value" style="left: {{ precip_proportion }}%;">{{ weather_now.precip }}#}
                            <div class="progress-value" style="left: 14%;">4
                            </div>  <!--rainfall_proportion = ma*0.78+5=left -->
                        </div>
                    </div>
                </div>
                <!-- 风速 -->
                <div class="dashboard-boot vertical-line col-md-4">
                    <div class="col-md-12">
{#                        <div class="row text-white justify-content-center">风速</div>#}
                        <div class="row text-white justify-content-center">高性能</div>
{#                        <div class="row text-gray justify-content-center">Wind Speed</div>#}
                        <div class="row text-gray justify-content-center">High-Performance</div>
{#                        <div class="row justify-content-center mt-2" style="color: #2ab62b; font-weight: bold;">{{ weather_now.wind_speed }}km/h#}
                        <div class="row justify-content-center mt-2" style="color: #2ab62b; font-weight: bold;">60%
                        </div>
                        <div class="row progress" style="height: 10px; width: 260px">
{#                            <div class="progress-bar" role="progressbar" aria-valuenow="50" aria-valuemin="0"#}
{#                                 aria-valuemax="100" style="width: {{ weather_now.wind_speed }}%;"></div>#}
                            <div class="progress-bar" role="progressbar" aria-valuenow="50" aria-valuemin="0"
                                 aria-valuemax="100" style="width: 60%;"></div>

{#                            <div class="progress-value" style="left: {{ wind_speed_proportion }}%;">{{ weather_now.wind_speed }}#}
                            <div class="progress-value" style="left: 53%;">60
                            </div>  <!--rainfall_proportion = ma*0.78+5=left -->
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- 中间,占宽度3格 -->
        <div class="panel-body col-md-3">
            <!-- 相对湿度 -->
            <div class="row">
                <div class="dashboard-right1 vertical-line">
                    <!--相对湿度-->
                    <div class="col-md-12">
                        <i class="d-flex bi bi-droplet text-info" style="justify-content: center;font-size: 1.5rem;"></i>
                        <div class="row" style="justify-content: center;color: white">相对湿度</div>
                        <div class="row" style="justify-content: center;color: grey">Relative Humidity</div>
                        <div class="row fs-5 mt-2" style="justify-content: center;color: #2ab62b; font-weight: bold;">{{ weather_now.humidity }}%</div>
                    </div>
                </div>
            </div>
            <!-- 洗车 -->
            <div class="row">
                <div class="dashboard-right1 vertical-line">
                    <div class="col-md-12">
                        <i class="d-flex bi bi-car-front-fill text-info" style="justify-content: center;font-size: 1.5rem;"></i>
                        <div class="row" style="justify-content: center;color: white">洗车</div>
                        <div class="row" style="justify-content: center;color: grey">Car Wash</div>
                        <div class="row mt-2" style="justify-content: center;color: #2ab62b; font-weight: bold;">{{ living_index.car_washing.brief }}</div>
                    </div>
                </div>
            </div>
            <!-- 旅游 -->
            <div class="row" >
                <div class="dashboard-right1 vertical-line" style="height: 29vh;">
                    <div class="col-md-12">
                        <i class="d-flex bi bi-gender-trans text-info" style="justify-content: center;font-size: 1.5rem;"></i>
                        <div class="row" style="justify-content: center;color: white">旅游</div>
                        <div class="row" style="justify-content: center;color: grey">Traveling Outside</div>
                        <div class="row mt-2 text-warning" style="justify-content: center; font-weight: bold;">{{ living_index.travel.brief }}</div>
                    </div>
                </div>
                </div>
            </div>
        <!-- 右边,占宽度2格 -->
        <div class="panel-body col-md-2">
             <div class="row">
               <div class="dashboard-right2-1 vertical-line">
                    <div class="col-md-12">
                        <div class="row text-warning" style="justify-content: center; font-size: 1rem;">{{ currentCity }}</div>
                        <i class="d-flex bi bi-cloud text-info mt-1" style="justify-content: center;font-size: 1.5rem;"></i>
                        <div class="row text-white mt-1" style="justify-content: center; font-size: 0.8rem;">白天:{{ weather_now.text_day }}, 晚上:{{ weather_now.text_night }}</div>
                        <div class="row mt-1" style="justify-content: center;color: grey; font-size: 0.8rem;">发布日期:{{ weather_now.date }}</div>
                    </div>
               </div>
             </div>

             <div class="row">
               <div class="dashboard-right2-2 vertical-line">
                   <div class="col-md-12">
                       <div class="row">
                           <div class="col-md-6 align-content-center">
                                <i class="d-flex bi bi-calendar4-week text-light" style="font-size: 2rem; justify-content: center"></i>
                            </div>
                           <div class="col-md-6 text-end">
                                <div class="me-3 text-white" style="font-size: 0.8rem">选择日期</div>
                                <div class="me-2 text-info" style="font-size: 0.7rem">
                                    <div class="row">
                                    <a type="button" style="text-decoration: none;" href="{% url 'index' aid=0 %}">{{ weather_now_a.date }}</a>
                                    <a type="button" style="text-decoration: none;" href="{% url 'index' aid=1 %}">{{ weather_two.date }}</a>
                                    <a type="button" style="text-decoration: none;" href="{% url 'index' aid=2 %}">{{ weather_three.date }}</a>
                                    </div>
                                </div>
                           </div>
                       </div>
                   </div>
               </div>
             </div>

             <div class="row">
               <div class="dashboard-right2-2 vertical-line">
                   <div class="col-md-12">
                       <div class="row">
                           <div class="col-md-6 align-content-center">
                                <i class="d-flex bi bi-wind text-light" style="font-size: 2rem; justify-content: center"></i>
                            </div>
                           <div class="col-md-6 text-end" id="clearWind">
                                <div class="me-3 text-white" style="font-size: 0.8rem">{{ weather_now.wind_direction }}风</div>
                                <div class="me-3 text-gray" style="font-size: 0.6rem">{{ weather_now.wind_scale }}级</div>
                           </div>
                       </div>
                   </div>
               </div>
             </div>

             <div class="row">
               <div class="dashboard-right2-2 vertical-line">
                   <div class="col-md-12">
                       <div class="row">
                           <div class="col-md-6 align-content-center">
                                <i class="d-flex fa fa-bicycle text-light" style="font-size: 2rem; justify-content: center"></i>
                            </div>
                           <div class="col-md-6 text-end">
                                <div class="me-3 text-white" style="font-size: 0.8rem">{{ living_index.sport.brief }}</div>
                                <div class="me-3 text-gray" style="font-size: 0.6rem">运动</div>
                           </div>
                       </div>
                   </div>
               </div>
             </div>

             <div class="row">
               <div class="dashboard-right2-2 vertical-line">
                   <div class="col-md-12">
                       <div class="row">
                           <div class="col-md-6 align-content-center">
                                <i class="d-flex bi bi-brightness-high text-light" style="font-size: 2rem; justify-content: center"></i>
                            </div>
                           <div class="col-md-6 text-end">
                                <div class="me-3 text-white" style="font-size: 0.8rem">{{ living_index.uv.brief }}</div>
                                <div class="me-3 text-gray" style="font-size: 0.6rem">紫外线</div>
                           </div>
                       </div>
                   </div>
               </div>
             </div>

             <div class="row">
               <div class="dashboard-right2-2 vertical-line">
                   <div class="col-md-12">
                       <div class="row">
                           <div class="col-md-6 align-content-center">
                                <i class="d-flex bi bi-universal-access text-light" style="font-size: 2rem; justify-content: center"></i>
                            </div>
                           <div class="col-md-6 text-end">
                                <div class="me-3 text-white" style="font-size: 0.8rem">{{ living_index.dressing.brief }}</div>
                                <div class="me-3 text-gray" style="font-size: 0.6rem">穿衣</div>
                           </div>
                       </div>
                   </div>
               </div>
             </div>

             <div class="row">
               <div class="dashboard-right2-2 vertical-line">
                   <div class="col-md-12">
                       <div class="row">
                           <div class="col-md-6 align-content-center">
                                <i class="d-flex bi bi-clipboard-plus text-light" style="font-size: 2rem; justify-content: center"></i>
                            </div>
                           <div class="col-md-6 text-end">
                                <div class="me-3 text-white" style="font-size: 0.8rem">{{ living_index.flu.brief }}</div>
                                <div class="me-3 text-gray" style="font-size: 0.6rem">感冒</div>
                           </div>
                       </div>
                   </div>
               </div>
             </div>

         </div>
  </div>

</div>
{% endblock %}


{% block js %}
{#<script src="https://cdn.jsdelivr.net/npm/echarts/dist/echarts.min.js"></script>#}
<script src="{% static 'js/echarts.min.js' %}"></script>
<script>
// 基于准备好的dom，初始化echarts实例
var temperatureChart = echarts.init(document.getElementById('temperature-chart'));
var humidityChart = echarts.init(document.getElementById('humidity-chart'));

// 指定图表的配置项和数据
var optionTemperature = {
  series: [
    {
      type: 'gauge',
      {#min: -50,                 // 最小的数据值,默认 0 。映射到 minAngle。#}
      {#max: 50,               // 最大的数据值,默认 100 。映射到 maxAngle。#}
      min: 0,                 // 最小的数据值,默认 0 。映射到 minAngle。
      max: 500,               // 最大的数据值,默认 100 。映射到 maxAngle。

      detail: {   // 指针底下的标题，一般是数据内容的值(动态显示)
            {#formatter: '{value}℃',#}
            formatter: '{value}V',
            offsetCenter: ['-3', '70%'],       // x, y，单位px
            textStyle: {       // 其余属性默认使用全局文本样式
                fontWeight: 'bolder',
                fontSize: 23,
                color: "pink"
            }
        },

        {#data: [{value: 0, name: '最高温度'}],#}
        data: [{value: 0, name: '电压'}],

        {#name: '右上转速', // 只做多表盘标记，没有实际用途#}
        {#center: ['33%', '33%'],    // 默认全局居中#}
        {#radius: '50%',#}
        {#clockwise:true, //仪表盘刻度顺时针增长#}
        {#min:0, // 刻度最小值#}
        {#max:90, // 刻度最大值#}
        {#startAngle:225, // 从哪里开始截断#}
        {#endAngle:45,    // 从哪里结束截断，这样能得到圆的一部分#}
        {#splitNumber:7, // 不太明白，有点像增加显示什么数字作为分割#}

         axisLine: {            // 坐标轴线(外框圆弧部分)
                lineStyle: {       // 属性lineStyle控制线条样式
                    width: 12,
                    color: [[1, '#3b3c40'],],  //0.2表示到20%这里结束 '#c23531', '#63869e', '#91c7ae' [0.8, '#3b3c40'], [1, '#3b3c40']
                    shadowBlur: 10, // 阴影效果
                    shadowColor: 'rgba(0, 0, 0, 0.6)',// 阴影效果
                }
            },

        progress: {  /* 圆弧边缘动态指示 */
            show: true,
            width: 12,
            {#overlap: false,#}
            {#roundCap: true,#}
            {#clip: false,#}
            itemStyle: {
            {#borderWidth: 6,#}
            {#borderColor: 'green',#}
            shadowBlur: 10,          // 阴影效果
            shadowColor: 'rgba(0, 0, 0, 0.6)', // 阴影效果
             }
        },

        axisTick: {            // 坐标轴小标记(圆弧里边刻度线,最短那根)
            distance: 5,       // 距离圆圈距离
            length: 6,        // 属性length控制线长
            lineStyle: {       // 属性lineStyle控制线条样式
                color: 'white'
            }
        },

        splitLine: {           // 分隔线
            distance: 5,       // 距离圆圈距离
            length: 10,         // 属性length控制线长(圆弧里面刻度线,最长那根)
            lineStyle: {       // 属性lineStyle（详见lineStyle）控制线条样式
                width: 2,
                color: 'white'
            }
        },

        pointer: {  // 指针的粗细
            width: 7,
        },

        title: {  // 指针上边的标题
            offsetCenter: ['0', '95%'],       // x, y，单位px
            fontSize: 18,
            color: 'grap'
        },

        axisLabel: {   // 刻度数字
            distance: 20,
            color: '#999',
            fontSize: 10
         },

        anchor: {  // 指针最中心圆形
            show: true,
            showAbove: true,
            size: 11,
            itemStyle: {
                borderWidth: 10
            }
        },
      // 其他配置项...
    }
  ]
 };

var optionHumidity = {

  series: [
    {
      type: 'gauge',
      min: 0,                 // 最小的数据值,默认 0 。映射到 minAngle。
      max: 500,               // 最大的数据值,默认 100 。映射到 maxAngle。
      detail: {   // 指针底下的标题，一般是数据内容的值(动态显示)
          {#formatter: '{value}℃',#}
          formatter: '{value}mA',
          offsetCenter: ['-3', '70%'],       // x, y，单位px
          textStyle: {       // 其余属性默认使用全局文本样式
              fontWeight: 'bolder',
              fontSize: 23,
              color: "#2ab62b"
          }
      },

      {#data: [{value: 0, name: '最低温度'}],#}
      data: [{value: 0, name: '电流'}],

         axisLine: {            // 坐标轴线(外框圆弧部分)
                lineStyle: {       // 属性lineStyle控制线条样式
                    width: 12,
                    color: [[1, '#3b3c40'],],  //0.2表示到20%这里结束 '#c23531', '#63869e', '#91c7ae' [0.8, '#3b3c40'], [1, '#3b3c40']
                    shadowBlur: 10, // 阴影效果
                    shadowColor: 'rgba(0, 0, 0, 0.6)',// 阴影效果
                }
            },

        progress: {  /* 圆弧边缘动态指示 */
            show: true,
            width: 12,
            {#overlap: false,#}
            {#roundCap: true,#}
            {#clip: false,#}
            itemStyle: {
            {#borderWidth: 6,#}
            {#borderColor: 'green',#}
            shadowBlur: 10,          // 阴影效果
            shadowColor: 'rgba(0, 0, 0, 0.6)', // 阴影效果
             }
        },

        axisTick: {            // 坐标轴小标记(圆弧里边刻度线,最短那根)
            distance: 5,       // 距离圆圈距离
            length: 6,        // 属性length控制线长
            lineStyle: {       // 属性lineStyle控制线条样式
                color: 'white'
            }
        },

        splitLine: {           // 分隔线
            distance: 5,       // 距离圆圈距离
            length: 10,         // 属性length控制线长(圆弧里面刻度线,最长那根)
            lineStyle: {       // 属性lineStyle（详见lineStyle）控制线条样式
                width: 2,
                color: 'white'
            }
        },

        pointer: {  // 指针的粗细
            width: 7,
        },

        title: {  // 指针上边的标题
            offsetCenter: ['0', '95%'],       // x, y，单位px
            fontSize: 18,
            color: 'grap'
        },

        axisLabel: {   // 刻度数字
            distance: 20,
            color: '#999',  //#2ab62b
            fontSize: 10
         },

        anchor: {  // 指针最中心圆形
            show: true,
            showAbove: true,
            size: 11,
            itemStyle: {
                borderWidth: 10
            }
        },
      // 其他配置项...
    }
  ]
 };

// 使用刚指定的配置项和数据显示图表。
temperatureChart.setOption(optionTemperature);
humidityChart.setOption(optionHumidity);

// 假设我们有一个函数来获取新的数据
var newTemperatureValue = 0;
var newHumidityValue = 0;
function updateChartsData() {
  {#var newTemperatureValue = getNewTemperatureValue(); // 假设这是一个获取新温度数据的函数#}
  {#var newHumidityValue = getNewHumidityValue(); // 假设这是一个获取新湿度数据的函数#}
  {#  newTemperatureValue += 2#}
  {#  newHumidityValue += 1#}

  newTemperatureValue = $('#temperatureP').text()  // 直接获取index返回给html的值就好
  newHumidityValue = $('#humidityP').text()        // 直接获取index返回给html的值就好

  // 更新仪表盘数据
  temperatureChart.setOption({
    series: [{
      {#data: [{value: newTemperatureValue, name: '最高温度'}]#}
      data: [{value: newTemperatureValue, name: '电压'}]
    }]
  });

  humidityChart.setOption({
    series: [{
      {#data: [{value: newHumidityValue, name: '最低温度'}]#}
      data: [{value: newHumidityValue, name: '电流'}]
    }]
  });
}
// 定时更新数据
{#setInterval(updateChartsData, 5000); // 每5秒更新一次数据#}
updateChartsData()
    </script>

{% endblock %}